package com.fosun.spr.core.base;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import com.alibaba.fastjson.JSONObject;
import com.fosun.spr.core.base.model.CoBaseSpModel;
import com.fosun.spr.core.proxy.aop.BaseAspect;

/**
 * SpringMVC的Control基类
 * 
 * @author Chen Shiming 陈市明 # SprCore Feb 22, 2017
 * @updater zhangcheng
 */
public abstract class CoBaseControl extends BaseAspect {
	protected static void debugPrintJsonSpModel(CoBaseSpModel spModel)
			throws Exception {
		Map map = BeanUtils.describe(spModel);
		Iterator<String> it = map.keySet().iterator();
		while (it.hasNext()) {
			String key = it.next();
			Object obj = map.get(key);
			// if (obj instanceof String) {
			if (obj == null && !"locale".equals(key)
					&& !"sessionTeamId".equals(key)
					&& !"sessionUserId".equals(key)) {
				try {
					BeanUtils.setProperty(spModel, key, "");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			// }
		}
		String json = JSONObject.toJSONString(spModel, true);
		System.out.println(spModel.getClass());
		System.out.println(json);
		System.out.println("");
	}

}
